Index

Overview


Serialization can go by a few different names:


To serialize a object means that to deconstruct the object to a simple form that can be stored or transmitted and most importantly reconstructed (deserialized) later.

We are familiar with objects in memory which are fully formed with their structure of instance variables (which may be other objects) and behaviors (methods).

A serialized (or deflated) object would be a representation of that object, often plain text.

Example of Class
Here is a class named "Lake" with six ivars.
public class Lake {
	private String name;
	private String county;
	private String nearbyTown;
	private int size; //acres
	private int maxDepth; //feet
	private int clarity; //feet (visibility)
	//...
}
Example of Object Values
Here is instance of the class with the six ivars populated.
name = Parkers
county = Hennepin
nearbyTown = Plymouth
size = 100
maxDepth = 37
clarity = 12


name=Parkers,county=Hennepin,nearbyTown=Plymouth,size=100,maxDepth=37,clarity=12

Serialization (Deflating)


The instance lives and flourishes in computer memory. However, when taken out of memory e.g. let's say for transmission across the web it has to be serialized (or in basic terms "simplified" or "deflated").

Let's put it into one simple String:

"Parkers,Hennepin,Plymouth,100,37,12"


We could make it more self-described by adding the ivar (field) names:

name=Parkers,county=Hennepin,nearbyTown=Plymouth,size=100,maxDepth=37,clarity=12


Deserialization (Inflating)


We need to be able to do the reverse. That is, an instance needs to be able to inflate or initialize itself from the previously deflated data.



Left: The Serialized or deflated form used for storage/transmission
Right: The inflated instance. In this conceptual example, the instance would simply parse the six comma separated values, and do any necessary conversions (e.g. String to int, etc), and then assign the values to it's instance variables.
"Parkers,Hennepin,Plymouth,100,37,12"
name = Parkers
county = Hennepin
nearbyTown = Plymouth
size = 100
maxDepth = 37
clarity = 12


name=Parkers,county=Hennepin,nearbyTown=Plymouth,size=100,maxDepth=37,clarity=12



Common Serialization Formats


Fortunately, serialization formats have gotten simpler with time.

These are two formats which both were designed with "user-friendliness" in mind: